home *** CD-ROM | disk | FTP | other *** search
Text File | 1992-10-09 | 1.3 KB | 41 lines | [TEXT/MEDT] |
- MODULE StringExample; (* shows the use of the string procedures *)
-
- FROM String IMPORT last, Length, Occurs, Copy;
- FROM InOut IMPORT termCH, WriteString, WriteLn, ReadString;
-
- VAR PathName : ARRAY [0..63] OF CHAR;
- FileName : ARRAY [0..31] OF CHAR;
-
- PROCEDURE SplitPath(VAR Path : ARRAY OF CHAR; VAR Name : ARRAY OF CHAR);
- (* splits a complete file name ('Path') into the actual path and the file name *)
- (* with the extension. The path is returned in 'Path', the file name in 'Name'.*)
- VAR i,j : INTEGER;
- BEGIN (* SplitPath *)
- (* Find last ":" in the path *)
- i := -1;
- WHILE (i < Length(Path)) DO (* Length(s) # HIGH(s) !! *)
- j := i;
- i := Occurs(Path,i+1,":");
- END (* WHILE *);
- INC(j);
- Copy(Name,Path,j,last);
- Path[j] := 0C; (* Quicker than 'Delete(Path,j,last)' *)
- END SplitPath;
-
- BEGIN (* StringExample *)
- LOOP
- WriteLn;
- WriteString("Enter a complete file name (including the path): ");
- ReadString(PathName);
- IF termCH < " " THEN
- WriteString(" -- escape"); EXIT;
- END (* IF *);
- SplitPath(PathName,FileName);
- WriteLn;
- WriteString(" The path name is : "); WriteString(PathName); WriteLn;
- WriteString(" The file name is : "); WriteString(FileName); WriteLn;
- WriteLn;
- END (* LOOP *);
- END StringExample.
-
-